package com.example.bigworkdemo.service;

import com.example.bigworkdemo.bean.user;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class userService {
    public user login(user user) throws Exception {
            if(user.getUsername().equals("test") && user.getPassword().equals("123456")){
                return new user("test",1001,"123456","1532893@qq.com","2020-12-12");
            }else
            {
                throw new Exception ("账号或密码错误");
            }
    }
    public user findUserByid(Integer id){
        if(id == 1001){
            return new user("test",1001,"123456","1532893@qq.com","2020-12-12");
        }
        else {
            return null;
        }
    }
    public int addUser(user u){
        user newUser = new user();
        newUser.setUserId(1002);
        newUser.setUsername(u.getUsername());
        newUser.setPassword(u.getPassword());
        newUser.setEmail(u.getEmail());
        newUser.setBirth(u.getBirth());
        System.out.println(newUser);
        return 1;
    }
    public int changeUser(user u){
        user newUser = new user();
        if(u.getUserId() == 1001){
            newUser.setUsername(u.getUsername());
            newUser.setPassword(u.getPassword());
            newUser.setEmail(u.getEmail());
            newUser.setBirth(u.getBirth());
            System.out.println(newUser);
            return 1;
        }
        else {
            return 0;
        }
    }
    public int delete(Integer id){
        if(id == 1001){
            return 1;
        }else {
            return 0;
        }
    }
    public List<user> getUserList(){
        List<user> list = new ArrayList<>();
        list.add(new user("test",1001,"123456","1532893@qq.com","2020-12-12"));
        list.add(new user("test2",1002,"123456","1532893@qq.com","2020-12-12"));
        list.add(new user("test3",1003,"1234516","15328193@qq.com","2020-12-12"));
        return list;
    }
}
